import Vue from 'vue'
import KendoConfirm from './KendoConfirm.vue'

const KendoConfirmConstructor = Vue.extend(KendoConfirm)

const ConfirmConstructor = function(confirmModalOptions) {
  return new Promise((res, rej) => { // promise封装，ok执行resolve，no执行rejectlet
    const confirmDom = new KendoConfirmConstructor({
      el: document.createElement('div')
    })
    this.$el.appendChild(confirmDom.$el) // new一个对象，然后插入body里面
    confirmDom.confirmModalOptions = confirmModalOptions // 为了使confirm的扩展性更强，这个采用对象的方式传入，所有的字段都可以根据需求自定义
    confirmDom.execute = function() {
      res()
      confirmDom.visibleDialog = false
    }
    confirmDom.cancel = function() {
      rej()
      confirmDom.visibleDialog = false
    }
  })
}

export default ConfirmConstructor
